﻿using System;
using System.Diagnostics;
using System.Reflection;

namespace Practical.SharePoint.Base
{
    static class AssemblyUtilities
    {
        public static string GetAssemblyFileVersion()
        {
            return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
        }

        public static string GetAssemblyDescription()
        {
            string returnValue = string.Empty;
            //Type of attribute that is desired
            Type type = typeof(AssemblyDescriptionAttribute);
            //Is there an attribute of this type already defined?
            if (Attribute.IsDefined(Assembly.GetExecutingAssembly(), type))
            {
                //if there is, get attribute of desired type
                AssemblyDescriptionAttribute a = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);
                returnValue = a.Description;
            }
            return returnValue;
        }

        public static string GetAssemblyConfiguration()
        {
            string returnValue = string.Empty;
            //Type of attribute that is desired
            Type type = typeof(AssemblyConfigurationAttribute);
            //Is there an attribute of this type already defined?
            if (Attribute.IsDefined(Assembly.GetExecutingAssembly(), type))
            {
                //if there is, get attribute of desired type
                AssemblyConfigurationAttribute a = (AssemblyConfigurationAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);
                returnValue = a.Configuration;
            }
            return returnValue;
        }
    }
}
